<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<title></title>
		<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/vant@2.5/lib/index.css">
		<link rel="stylesheet" href="/statics/wxdemo/css/reset.css">
		<link rel="stylesheet" href="/statics/wxdemo/css/global.css">
		<link rel="stylesheet" href="/statics/wxdemo/css/newfriendask.css">
		<script src="/statics/wxdemo/js/flexble.js"></script>
		<script src="https://cdn.jsdelivr.net/npm/vue@2.6.11"></script>
		<script src="https://cdn.jsdelivr.net/npm/vant@2.5/lib/vant.min.js"></script>
		<script type="text/javascript" src="/statics/wxdemo/sdk/webimSDK3.1.2.js"></script>
		<script type="text/javascript" src="/statics/wxdemo/js/WebIMConfig.js"></script>
		<script type="text/javascript" src="/statics/wxdemo/js/webconn.js"></script>
		<script type="text/javascript" src="/statics/wxdemo/js/localstorage.js"></script>
		<script type="text/javascript" src="/statics/wxdemo/utils/login.js"></script>
		<script type="text/javascript" src="/statics/wxdemo/utils/dialog.js"></script>
	</head>
	<body>
		<div class="newfriendaskBox" id="bigbox">
			<div class="fixedtop">
				<div class="getBack">
					<van-button class="arrowbox" type="default" @click="back">
						<img src="/statics/wxdemo/img/back.png">
					</van-button>
					<p class="fixedtoptit">新的朋友</p>
				</div>
			</div>
			<van-pull-refresh v-model="isLoading" @refresh="onRefresh">
				<div class="newfriendaskList">
					<div class="chatlistbox" v-for="(item,index) in AskList" :key="index">
						<div class="avatarbox">
							<img class="avatar" src="/statics/wxdemo/img/avatar.jpg">
						</div> 
						<div class="chatlist_rightbox">
							<div class="chatlistmidbox">
								<p class="chatname">{{item.from}}</p>
								<p class="chatlastmes">{{item.status}}</p>
							</div>
							<div class="chatlist_leftbox">
								<van-button plain type="primary" v-if="!item.isadd" @click="acceptask(item)">同意</van-button>
								<p v-if="item.isadd">已添加</p>
							</div>
						</div>
					</div>
				</div>
			</van-pull-refresh>
		</div>
	</body>
</html>
<script type="text/javascript">
WebIM.message = WebIM.default.message;
var webvue = new Vue({
	el: '#bigbox',
	data() {
		return {
			AskList:getStorage('friendAskList'),
			isLoading: false,
		}
	}, 
	mounted(){
		isfirst = 6;
		relogin()
		setTimeout(()=>{
			console.log(getStorage('friendAskList'))
		},1000)
	},
	methods:{
		back(){
			window.history.go(-1);
		},
		onRefresh(){
			console.log('哈哈哈')
			this.isLoading = false;
			this.AskList = getStorage('friendAskList')
		},
		acceptask(item){
			var that = this;
			var friendAskList = this.AskList;
			console.log(friendAskList)
			if (item.type === 'subscribe') {			  
			    /*同意添加好友操作的实现方法*/
			    conn.subscribed({
			      to: item.from,
			      message : '[resp:true]'
			    });
				friendAskList.forEach((items,index)=>{
					 if(items.from == item.from){
						 items.isadd = true;
					 }
				})
				setTimeout(()=>{
					window.location.href = '/Welcome/addressbook';
				},500)
			  }else if(item.type === 'joinGroupNotifications'){
				  /*同意对方入群申请*/
				  var options = {
					  applicant: item.from,                          // 申请加群的用户名
					  groupId: item.groupid,                              // 群组ID
					  error: function(e){}
				  };
				  conn.agreeJoinGroup(options);
				  friendAskList.forEach((items,index)=>{
				  	 if(items.from == item.from){
				  		 items.isadd = true;
				  	 }
				  })
				  setTimeout(()=>{
				  	window.location.href = '/Welcome/groupbook';
				  },500)
			  }
			  saveStorage('friendAskList',friendAskList)
		},
	}
})
</script>